#include "com.h"

int main()
{
  key_t key = ftok(PATH_NAME, PROJ_ID);
  if(key < 0)
  {
    perror("ftok");
    return 1;
  }
  //printf("%d\n",key);

  int shmid = shmget(key, SIZE, IPC_CREAT|IPC_EXCL|0666);
  if(shmid < 0)
  {
    perror("shmget");
    return 1;
  }
  //printf("%d\n", shmid);

  char* mem = (char*)shmat(shmid, NULL, 0);//将共享内存段连接到进程地址空间
  //进程通信的逻辑
  while(1)
  {
    sleep(1);
    printf("%s\n", mem);
  }

  shmdt(mem);//将共享内存段与当前进程脱离

  shmctl(shmid, IPC_RMID, NULL);
  return 0;
}
